<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
</html>
<script>
  function add(...a) {
    // console.log(a);
    // 处理参数的累加，返回累加的结果
    // ...a 剩余参数
    // console.log(a);
    // console.log(arguments);
    // let b =
    // for (let i = 0; i < a.length; i++) {
    //   b += a[i];
    // }
    return a.reduce((a, b) => {
      console.log(a);
      return a + b.num;
    }, 0);
  }

  //   console.log(add({ num: 1 }, { num: 2 }, { num: 3 }, { num: 4 }, { num: 5 }));

  //   let arr = [1, 2, 3, 4, 5, 5, 4, 3, 6];
  //   console.log(new Set(arr));
  //   let arr1 = [...new Set(arr)];
  //   console.log(arr1);

  let arr = [
    { id: 1, name: "马云" },
    { id: 2, name: "马化腾" },
    { id: 3, name: "李彦宏" },
    { id: 2, name: "小马云" },
    { id: 3, name: "小马" },
  ];
  //   let arr1 = [];
  //   let arr2 = [];
  //   arr.forEach((item) => {
  //     if (!arr2.includes(item.id)) {
  //       arr2.push(item.id);
  //       arr1.push(item);
  //     }
  //   });
  //   console.log(arr2);
  //   console.log(arr1);

  function redu(arr) {
    let seen = [];
    return arr.filter((item) => !seen.includes(item.id) && seen.push(item.id));
  }
  console.log(redu(arr));
</script>
